﻿Imports SS.ApplicationBlock.Security

Public Class ViewStatusRegister
	Inherits System.Web.UI.Page

	Public Function EncyId(ByVal officerId As String) As String
		Return "~/ViewOtherProfile.aspx?officerid=" & DES.EncryptString(officerId, BL.SystemConfig.GetDESKey)
	End Function

	Public Shared Function ConvertStatus(ByVal status As String) As String
		Return Common.Utility.ConvertStatus(status)
	End Function

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

	End Sub

	Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
		Dim strFrom As String = String.Empty
		Dim strTo As String = String.Empty

		If Not String.IsNullOrEmpty(Me.ccFrom.value) Then
			Dim dteFrom As New DateTime(Me.ccFrom.Year, Me.ccFrom.Month, Me.ccFrom.Day)
			strFrom = Common.UtilityDateTime.ConvertDateToString(dteFrom)
		End If

		If Not String.IsNullOrEmpty(Me.ccTo.value) Then
			Dim dteTo As New DateTime(Me.ccTo.Year, Me.ccTo.Month, Me.ccTo.Day)
			strTo = Common.UtilityDateTime.ConvertDateToString(dteTo)
		End If

		Me.Session(GlobalApp.sessionName) = BL.Officer.LoadOfficerInputer(Me.txtNameTh.Text, Me.txtAppId.Text, strFrom, strTo, GlobalApp.Authen.offcier_id)
		BindGrid(0)
	End Sub

	Public Sub BindGrid(ByVal pageIndex As Integer)
		Me.gvList.PageIndex = pageIndex
		Me.gvList.DataSource = Me.Session(GlobalApp.sessionName)
		Me.gvList.DataBind()
	End Sub

	Protected Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
		BindGrid(e.NewPageIndex)
	End Sub

	Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
		Me.txtAppId.Text = String.Empty
		Me.txtNameTh.Text = String.Empty
		Me.ccFrom.value = String.Empty
		Me.ccTo.value = String.Empty
	End Sub

	Protected Sub gvList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvList.SelectedIndexChanged

		Try
			GlobalApp.DataSourceEditOfficer = BL.Officer.LoadProfile(Me.gvList.SelectedValue)
		Catch ex As Exception
			Me.Master.Alert("ไม่สามารถดึงข้อมูลที่ท่านต้องการได้")
			Common.LogError.AddLogException(ex)
		End Try

		Dim officer As Entity.OfficerInfoItem = GlobalApp.DataSourceEditOfficer
		If officer.officer_type.Equals("O") Then
			Response.Redirect("~/EditStaff.aspx", False)
		Else
			Response.Redirect("~/EditApplication.aspx", False)
		End If

	End Sub

	Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPDF.Click
		If Me.Session(GlobalApp.sessionName) Is Nothing Then
			Exit Sub
		End If
		Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "ut203", "window.open('report/exportpdf.aspx?rptname=ut203', 'exportpdf','')", True)
		Me.Session("reportdatasource") = Me.Session(GlobalApp.sessionName)
	End Sub

	Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExcel.Click
		If Me.Session(GlobalApp.sessionName) Is Nothing Then
			Exit Sub
		End If
		Dim dt As DataTable = Me.Session(GlobalApp.sessionName)
		For Each dr As DataRow In dt.Rows
			dr("OFFICER_STATUS") = Common.Utility.ConvertStatus(dr("OFFICER_STATUS"))
		Next
		Common.Utility.ExportToSpreadsheet(GridView1, dt, "registeronline")
	End Sub
End Class